home *** CD-ROM | disk | FTP | other *** search
/ InterCD 2000 September / september_2000.iso / intercd / root / ^Linux / WindowMaker / test / notest.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-09-29  |  3.3 KB  |  136 lines

  1. /* quick and dirty test application that demonstrates: Notify grabbing
  2.  *
  3.  * TODO: remake
  4.  */
  5.  
  6. #include <stdio.h>
  7. #include <X11/Xlib.h>
  8. #include <X11/Xutil.h>
  9. #include <X11/Xproto.h>
  10. #include <WMaker.h>
  11.  
  12.  
  13. Display *dpy;
  14. Window leader;
  15. WMAppContext *app;
  16. Atom delete_win;
  17. Atom prots[6];
  18. XWMHints *hints;
  19. WMMenu *menu;
  20.  
  21.  
  22. static void
  23. quit(void *foo, int item, Time time)
  24. {
  25.     exit(0);
  26. }
  27.  
  28.  
  29. static void
  30. hide(void *foo, int item, Time time)
  31. {
  32.     WMHideApplication(app);
  33. }
  34.  
  35.  
  36. int notify_print( int id, XEvent *event, void *data )
  37. {
  38.     printf( "Got notification 0x%x, window 0x%lx, data '%s'\n",
  39.         id, event->xclient.data.l[1], (char *) data );
  40.     return True;
  41. }
  42.  
  43.  
  44. static void 
  45. newwin(void *foo, int item, Time time)
  46. {
  47.     Window win;
  48.     XClassHint classhint;
  49.     char title[100];
  50.  
  51.     win = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 
  52.                   0, 0, 200, 100, 0, 0, 0);
  53.     prots[0] = delete_win;
  54.     XSetWMProtocols(dpy, win, prots, 1);
  55.     sprintf(title, "Notify Test Window");
  56.     XStoreName(dpy, win, title);
  57.     
  58.     /* set class hint */
  59.     classhint.res_name = "notest";
  60.     classhint.res_class = "Notest";
  61.     XSetClassHint(dpy, win, &classhint);
  62.  
  63.     hints = XAllocWMHints();
  64.     /* set window group leader */
  65.     hints->window_group = leader;
  66.     hints->flags = WindowGroupHint;
  67.     XSetWMHints(dpy, win, hints);
  68.  
  69.     WMAppAddWindow(app, win);   
  70.     XMapWindow(dpy, win);
  71. }
  72.  
  73. int main(int argc, char **argv)
  74. {    
  75.     XClassHint classhint;
  76.  
  77.     dpy = XOpenDisplay("");
  78.     if (!dpy) {
  79.     puts("could not open display!");
  80.     exit(1);
  81.     }
  82.     delete_win = XInternAtom(dpy, "WM_DELETE_WINDOW", False);
  83.  
  84.     leader = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 10, 10, 10, 10,
  85.                   0, 0, 0);
  86.     /* set class hint */
  87.     classhint.res_name = "notest";
  88.     classhint.res_class = "Notest";
  89.     XSetClassHint(dpy, leader, &classhint);
  90.  
  91.     /* set window group leader to self */
  92.     hints = XAllocWMHints();
  93.     hints->window_group = leader;
  94.     hints->flags = WindowGroupHint;
  95.     XSetWMHints(dpy, leader, hints);
  96.  
  97.     /* create app context */
  98.     app = WMAppCreateWithMain(dpy, DefaultScreen(dpy), leader);
  99.     menu = WMMenuCreate(app, "Notify Test Menu");
  100.     WMMenuAddItem(menu, "Hide", (WMMenuAction)hide, NULL, NULL, NULL);
  101.     WMMenuAddItem(menu, "Quit", (WMMenuAction)quit, NULL, NULL, NULL);
  102.     
  103.     WMAppSetMainMenu(app, menu);
  104.     WMRealizeMenus(app);
  105.  
  106.     /* Get some WindowMaker notifications */
  107.     WMNotifySet( app, WMN_APP_START, notify_print, (void *) "App start" );
  108.     WMNotifySet( app, WMN_APP_EXIT,  notify_print, (void *) "App end" );
  109.     WMNotifySet( app, WMN_WIN_FOCUS,  notify_print, (void *) "Focus in" );
  110.     WMNotifySet( app, WMN_WIN_UNFOCUS,  notify_print, (void *) "Focus out" );
  111.     WMNotifySet( app, WMN_NOTIFY_ALL,  notify_print, (void *) "Unknown type" );
  112.     WMNotifyMaskUpdate( app );    /* Mask isn't actually set till we do this */
  113.  
  114.     /* set command to use to startup this */
  115.     XSetCommand(dpy, leader, argv, argc);
  116.     
  117.     /* create first window */
  118.     newwin(NULL, 0, 0);
  119.  
  120.  
  121.     XFlush(dpy);
  122.     while( 1 ) {
  123.     XEvent ev;
  124.     XNextEvent(dpy, &ev);
  125.     if (ev.type==ClientMessage) {
  126.         if (ev.xclient.data.l[0]==delete_win) {
  127.         XDestroyWindow(dpy,ev.xclient.window);
  128.         break;
  129.         } 
  130.     } 
  131.     WMProcessEvent(app, &ev);
  132.     }
  133.     exit(0);
  134. }
  135.  
  136.